#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
void BubbleSort1(int* x, int n)
{
	int i = 0;
	int j = 0;
	for (i; i< n - 1; i++)
	{
		for (j = 0; j < n - 1 - i; j++)
		{
			if (x[j] < x[j + 1])
			{
				int tmp = x[j + 1];
				x[j + 1] = x[j];
				x[j] = tmp;
			}
		}
	}
}
void BubbleSort2(int* x, int m)
{
	int i = 0;
	int j = 0;
	for (i; i < m - 1; i++)
	{
		for (j = 0; j < m - 1 - i; j++)
		{
			if (x[j] > x[j + 1])
			{
				int tmp = x[j + 1];
				x[j + 1] = x[j];
				x[j] = tmp;
			}
		}
	}
}
void Print(int* x, int n)
{
	int i = 0;
	for (i; i < n; i++)
	{
		printf("%d ", x[i]);
	}
	printf("\n");
}
void Swap(int* x, int m, int* y, int n)
{
	int i = 0;
	if (m > n)
	{
		for (i = 0; i < m; i++)
		{
			int tmp = y[i];
			y[i] = x[i];
			x[i] = tmp;
		}
	}
	else
	{
		for (i = 0; i < n; i++)
		{
			int tmp = y[i];
			y[i] = x[i];
			x[i] = tmp;
		}
	}
}
int  Read(int* x)
{
	int i = 0;
	while (1)
	{
		scanf("%d", &x[i]);
		if (x[i] == 0)
			break;
		i++;
	}
	return i;
}
int main()
{
	int arr1[20] ;
	int arr2[20] ;
	int m = Read(arr1);
	int n = Read(arr2);
	Swap(arr1, m, arr2, n);
	//BubbleSort1(arr1, n);
	Print(arr1, n);
	//BubbleSort1(arr2, m);
	Print(arr2, m);
	BubbleSort2(arr1, n);
	Print(arr1, n);
	BubbleSort2(arr2, m);
	Print(arr2, m);
	return 0;
}